
export const messageMap:Record<string, any> = {};

export function registerMessage(type: string, callback: Function) {
  messageMap[type] = async (config:{
    webviewView:any,
    originalType:string
  }, payload:any) => {
    const { webviewView, originalType } = config;
    const res = await callback?.(payload);
    // 将结果返回给 Webview

    console.log('registerMessage', originalType, res);
    webviewView.webview.postMessage({
      type: originalType,
      payload: res,
    });
  };
}

export function unregisterMessage(type: string) {
  delete messageMap[type];
}
